package com.example.auth.service;

import com.example.common.plugins.authentication.ExampleUserInfoService;
import com.example.starter.util.Response;
import com.example.system.api.UserApi;
import com.example.system.dto.UserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author 王令
 * @since 2022/7/29 18:07
 */
@Service
@RequiredArgsConstructor
public class ExampleUserDetailsService implements ExampleUserInfoService, UserDetailsService {

    private final UserApi userApi;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Response<UserInfo> response = userApi.loadByUsername(username);
        return getUserDetailsInfo(response);
    }
}
